<% shipments ||= order.shipments %>

<% if order.order_refunded? || order.partially_refunded? %>
  <div class="alert-warning mb-5 py-2 px-3">
    <% i18n_key_suffix = "#{shipments.shipped_but_canceled.any? ? 'refunded' : 'canceled'}.#{order.partially_refunded? ? 'partially' : 'fully'}" %>

    <% if order.respond_to?(:gift_card) && order.gift_card.present? %>
      <% key = "storefront.refund_action_required_message.order_#{i18n_key_suffix}" %>
      <%= Spree.t(key, customer_support_email: order.store.customer_support_email ) %>
    <% else %>
      <% key = "storefront.refund_action_not_required_message.order_#{i18n_key_suffix}" %>
      <%= Spree.t(key) %>
    <% end %>
  </div>
<% end %>

<p class="mb-6">
  <%= I18n.t('activerecord.attributes.spree/order.completed_at') %> <%= local_time(order.completed_at) %>
</p>

<%== color_options_style_for_line_items(shipments.flat_map(&:line_items)) %>

<ul>
  <%= render partial: 'spree/shared/order_shipment', collection: shipments, as: :shipment, cached: spree_storefront_base_cache_scope %>
</ul>

<% if order.special_instructions.present? %>
  <div class="p-4 lg:p-6 text-sm border">
    <div class="uppercase tracking-widest mb-2">
      <%= I18n.t('activerecord.attributes.spree/order.special_instructions') %>
    </div>
    <div class="!leading-[1.375rem] text-neutral-800">
      <%= simple_format(order.special_instructions) %>
    </div>
  </div>
<% end %>

<div class="mt-6 bg-accent mb-24">
  <div class="grid grid-cols-1 lg:grid-cols-2 gap-4 lg:gap-6 p-4 lg:p-6 text-sm bg-border bg-accent-100">
    <% if order.billing_address.present? %>
      <!-- billing address -->
      <div>
        <div class="uppercase tracking-widest mb-2">
          <%= Spree.t(:billing_address) %>
        </div>
        <div class="!leading-[1.375rem] text-neutral-800">
          <%= render 'spree/shared/address', address: order.billing_address %>
        </div>
      </div>
    <% end %>
    <% if order.payments.valid.any? %>
      <!-- payment into -->
      <div class="mb-5 lg:mb-0">
        <div class="uppercase tracking-widest mb-2">
          <%= Spree.t(:payment_information) %>
        </div>
        <div class="!leading-[1.375rem] text-neutral-800">
          <%= render collection: order.payments.valid, partial: 'spree/shared/payment', cached: spree_storefront_base_cache_scope %>
        </div>
      </div>
    <% end %>
  </div>
  <!-- totals/summary -->
  <div class="p-4 lg:p-6 text-sm">
    <div class="flex items-center justify-between py-2">
      <div>
        <%= Spree.t(:subtotal) %>
      </div>
      <div>
        <%= order.display_item_total.to_html %>
      </div>
    </div>
    <div class="flex items-center justify-between py-2">
      <div>
        <%= Spree.t(:shipping) %>
      </div>
      <div>
        <%= order.display_ship_total.to_html %>
      </div>
    </div>
    <% if order.promo_total != 0 %>
      <div class="flex items-center justify-between py-2">
        <div>
          <%= Spree.t(:discount) %>
        </div>
        <div>
          <%= order.display_promo_total.to_html %>
        </div>
      </div>
    <% end %>
    <div class="flex items-center justify-between py-2">
      <div>
        <%= Spree.t(:tax) %>
      </div>
      <div>
        <%= order.display_tax_total.to_html %>
      </div>
    </div>

    <% if order.respond_to?(:gift_card) && order.gift_card.present? %>
      <div class="flex items-center justify-between py-2">
        <div><%= Spree.t(:gift_card) %></div>
        <div>-<%= order.display_gift_card_total.to_html %></div>
      </div>
    <% elsif order.using_store_credit? %>
      <div class="flex items-center justify-between py-2">
        <div><%= Spree.t(:store_credits) %></div>
        <div><%= order.display_total_applied_store_credit %></div>
      </div>
    <% end %>

    <div class="flex items-center justify-between text-lg pt-4 font-medium border-default border-t">
      <div>
        <%= Spree.t(:total) %>
      </div>
      <div>
        <%= order.display_total_minus_store_credits.to_html %>
      </div>
    </div>
  </div>
</div>
